using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PACKETPARSERMAX20.CORE;

namespace PACKETPARSERMAX20.CORE.DEFINITIONS
{
    public class SMSG_SPELLNONMELEEDAMAGELOG_DEF : DefinitionBase
    {
        public SpellNonMeleeDamageLog spellNonMeleeDamageLog = new SpellNonMeleeDamageLog();

        public override bool Process()
        {
            ResetPosition();

           // InitLog(); //start the log

            spellNonMeleeDamageLog.targetguid = popGuid();
            spellNonMeleeDamageLog.guid = popGuid();
            spellNonMeleeDamageLog.spellid = ReadUInt32();
            spellNonMeleeDamageLog.damagestats = ReadUInt32();

            if (ClientBuild >= 9183)
            {
                spellNonMeleeDamageLog.unk1 = ReadUInt32(); //wotlk
            }
            spellNonMeleeDamageLog.damageschoolmask = ReadByte();                       // spell school
            spellNonMeleeDamageLog.absorbeddamage = ReadUInt32();                        // AbsorbedDamage
            spellNonMeleeDamageLog.resist = ReadUInt32();                                 // resist
            spellNonMeleeDamageLog.physicaldamage = ReadByte();                         // if 1, then client show spell name (example: %s's ranged shot hit %s for %u school or %s suffers %u school damage from %s's spell_name
            spellNonMeleeDamageLog.isfromaura = ReadByte();                                       // unk isFromAura
            spellNonMeleeDamageLog.blocked = ReadUInt32();                                // blocked
            spellNonMeleeDamageLog.hittype = ReadUInt32();             // hitType, flags: 0x2 - SPELL_HIT_TYPE_CRIT, 0x10 - replace caster?
            spellNonMeleeDamageLog.isdebug = ReadByte();                                      // isDebug?

            //spellNonMeleeDamageLog.LogIt(this);

            var obj = Core.GetObject(spellNonMeleeDamageLog.guid);
            if (obj != null && obj.TypeID == TypeID.TYPEID_UNIT)
            {
                obj.UpdateAuraInfo(this);
            }


            return Validate();
        }



        public class SpellNonMeleeDamageLog
        {
            public ulong targetguid { get; set; }
            public ulong guid { get; set; }
            public uint spellid { get; set; }
            public uint damagestats { get; set; }
            public uint unk1 { get; set; }
            public byte damageschoolmask { get; set; }
            public uint absorbeddamage { get; set; }
            public uint resist { get; set; }
            public byte physicaldamage { get; set; }
            public byte isfromaura { get; set; }
            public uint blocked { get; set; }
            public uint hittype { get; set; }
            public byte isdebug { get; set; }



            //public void LogIt(DefinitionBase defbase)
            //{
            //    if (defbase.LogIt)
            //    {
            //     //   defbase.LogAppendLine("UInt64", "guid", guid, true);
            //     //   defbase.LogAppendLine("UInt64", "targetguid", targetguid, true);
            //     //   defbase.LogAppendLine("UInt32", "SpellID", spellid);
            //     //   defbase.LogAppendLine("UInt32", "Damagestats", damagestats);
            //     //   defbase.LogAppendLine("UInt32", "unk1", unk1);
            //     //   defbase.LogAppendLine("byte", "damageSchoolMask", damageschoolmask);
            //     //   defbase.LogAppendLine("UInt32", "AbsorbedDamage", absorbeddamage);
            //     //   defbase.LogAppendLine("UInt32", "Resist", resist);
            //     //   defbase.LogAppendLine("byte", "PhysicalDamage", physicaldamage);
            //     //   defbase.LogAppendLine("byte", "isFromAura", isfromaura);
            //     //   defbase.LogAppendLine("UInt32", "Blocked", blocked);
            //     //   defbase.LogAppendLine("UInt32", "hitType", hittype);
            //     //   defbase.LogAppendLine("byte", "isDebug", isdebug);

            //    }
            //}
        }
    }
}
